`
https://leetcode.cn/problems/combinations/
`

/**
 * @param {number} n
 * @param {number} k
 * @return {number[][]}
 */
var combine = function (n, k) {
  const res = []

  const track = []

  const backtrack = (start) => {
    // 遍历到了第 k 层，收集当前节点的值
    if (track.length === k) {
      res.push([...track])
      return
    }

    for (let i = start; i <= n; i++) {
      // 做选择
      track.push(i)
      // 回溯遍历下一层节点
      backtrack(i + 1)
      // 撤销选择
      track.pop()
    }
  }
  backtrack(1)
  return res
};